package com.vipshop.core.base.impl;

import com.vipshop.core.base.BaseRepository;
import com.vipshop.core.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;

/**
 * @author sxzku
 * @version 1.0
 * @className BaseServiceImpl
 * @description TODO
 * @date 2019/3/10 13:00
 **/
public class BaseServiceImpl<T,PrimaryKey extends Serializable> implements BaseService<T, PrimaryKey> {
    @Autowired
    BaseRepository<T, PrimaryKey> repository;
    @Override
    public T getById(PrimaryKey id) {
        return repository.getOne(id);
    }

    @Override
    public List<T> findAll() {
        return repository.findAll();
    }
    @Override
    public List<T> findAll(Sort sort) {
        return repository.findAll(sort);
    }

    @Override
    public List<T> findAllById(Iterable<PrimaryKey> ids) {
        return repository.findAllById(ids);
    }

    @Override
    public void deleteInBatch(Iterable<T> entities) {
        repository.deleteInBatch(entities);
    }

    @Override
    public void deleteAllInBatch() {
        repository.deleteAllInBatch();
    }

    @Override
    public T save(T entity) {
        return repository.save(entity);
    }

    @Override
    public List<T> saveAll(Iterable<T> entities) {
        return repository.saveAll(entities);
    }

    @Override
    public T saveAndFlush(T entity) {
        return repository.saveAndFlush(entity);
    }

    @Override
    public List<T> findAll(Example<T> example){
        return repository.findAll(example);
    }

    @Override
    public List<T> findAll(Example<T> example, Sort sort) {
        return repository.findAll(example,sort);
    }
}
